package com.smzd.framework.system.domain;

import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.smzd.core.domain.BaseOwnedEntity;
import com.smzd.framework.annotation.ModuleGroup;

@ModuleGroup("system")
public class User extends BaseOwnedEntity<Meeting> implements UserDetails {
	private static final long serialVersionUID = -3423653048966480846L;

	public static final int USER_TYPE_INVALID = -2;// 无效身份
	public static final int USER_TYPE_UNKOWN = -1;// 未知身份
	public static final int USER_TYPE_LOCKED = 0;// 未审核通过的用户，或被锁定的用户。不会拥有任何权限操作。默认创建用户类型
	public static final int USER_TYPE_MEETING_MANAGER = 1;// 系统管理员--使用所分配的权限在自己owner所指向的会务中进行操作管理
	public static final int USER_TYPE_MEETING_OWNER = 2;// 会务管理员--可以选择会务；行使owner为自己的会务中所有的权限。

	private String password;
	private int gender;
	private int type;
	private String email;
	private String mobile;
	private String avatar;
	
	private boolean security;  

	private List<Group> groups;
	private List<Role>	roles;
	
	public User(){}
	public User(int id){
		this.id = id;
	}
	public User(int id, String name){
		this.id = id;
		this.name = name;
	}
	public User(int id, String name, String password){
		this.id = id;
		this.name = name;
		this.password = password;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	@Override
	protected void extStrings(StringBuffer sb) {
		super.extStrings(sb);
		sb.append(", password: \"").append(password).append("\"")
				.append(", gender: ").append(gender)
				.append(", type: ").append(type);
	}

	public List<Group> getGroups() {
		return groups;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	/////////////////////Spring-Security-Framework////////////////
	
	private List<GrantedAuthority> authorities;
	
	@Override
	public List<GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getUsername() {
		return this.name;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return !disabled;
	}
	public void setAuthorities(List<GrantedAuthority> authorities) {
		this.authorities = authorities;
	}
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	boolean isSecurity() {
		return security;
	}
	void setSecurity(boolean security) {
		this.security = security;
	}
	public String getAvatar() {
		return avatar;
	}
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
}
